//////////////////////////page_orderDetails/////////////////////
$(document).on("pageInit", "#page_orderDetails", function(e, pageId, $page) {
    my.givetitle('订单详细');
                    key=my.get_key(my.getCookie('token'))
					var details=JSON.parse(sessionStorage.orderDetails)
					console.log(details)
					var cardetails=JSON.parse(sessionStorage.rentalCalDetails)
					console.log(cardetails)
					$('.cp').text(cardetails.usercar_nickname)
					$('.dd').text(sessionStorage.car_place_name)
					$('.clxh').text(cardetails.brand_chinese_name+' '+cardetails.cars_name)
					$('.qcsj').text(sessionStorage.rangTimeStart+":00")
					$('.hcsj').text(sessionStorage.rangTimeEnd+":00")
					$('.festival_price').text(config.danwei+cardetails.festival_price)
					$('.week_price').text(config.danwei+cardetails.week_price)
					$('.work_day_price').text(config.danwei+cardetails.work_day_price)
					$('#ddzy').text(config.danwei+details.order_allcost)
					//获取余额
	                        var info_ye={
	                        	   user_id:my.getCookie('id'),
      				        }
      				        info_ye=my.cryptoASEencrypt(JSON.stringify(info_ye),key)
      				        $.ajax({
      					       url:api.getuserbalancea,
      					       type: 'post',
      					       async:true,
      					       data:{'api_value':info_ye},
      					       error:function(){

      					       	   $.toast("获取失败");},
      					       success:function(data){
      						     if(data.match("err_code")!=null){
      							    switch(JSON.parse(data).err_code)
      								{
      									case 40003:

      									   my.tokenExpire()
      									   break;
      									default:

      									   $.toast(JSON.parse(data).err_msg);
      								}
      						       }else{
      						     	     data=JSON.parse(data)
      								     data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								     $('.ye').text(config.danwei+data[0].balancea_ccount)
      							}
      					    }
      			         })
      				//获取余额end
					//获取优惠券start
	                        var info_yh={
	                        	   user_id:my.getCookie('id'),
	                        	   cars_id:cardetails.cars_id,
      					           usercar_id:cardetails.usercar_id,
      					           store_id:sessionStorage.car_place,
      					           start_time:sessionStorage.rangTimeStart,
      					           end_time:sessionStorage.rangTimeEnd,
      					           brand_id:cardetails.brand_id
      				        }
	                        console.log(info_yh)
      				        info_yh=my.cryptoASEencrypt(JSON.stringify(info_yh),key)
      				        $.ajax({
      					       url:api.availablecoupons,
      					       type: 'post',
      					       async:true,
      					       data:{'api_value':info_yh},
      					       error:function(){

      					       	   $.toast("优惠券接口调用出错");},
      					       success:function(data){
      						     if(data.match("err_code")!=null){
      							    switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									case 50307:
      									   //用户没有优惠券，不进行提升
      									   break
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      						        }else{

      						     	     data=JSON.parse(data)
      								     data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								     console.log(data)
      								     for(i=0;i<data.length;i++){
      								     	 var option_str='<option title="'+data[i].coupon_value+'" value="'+data[i].coupon_used_id+'">'+data[i].coupon_name+'('+data[i].coupon_value+')</option>'
      								         $('.yhq_s').append(option_str)
      								     }
      								      $('.yhq_s').change(function(){
      								     	$('.yhq div span:first').text(config.danwei+$('.yhq_s option:checked').attr('title'))
      								     })
      							}
      					    }
      			         })
      				//获取优惠券end
      				//获取保险套餐start
      				 var info_baoxian={
	                        	   user_id:my.getCookie('id'),
      				        }
      				        info_baoxian=my.cryptoASEencrypt(JSON.stringify(info_baoxian),key)
      				        $.ajax({
      					       url:api.insurancelist,
      					       type: 'post',
      					       async:true,
      					       data:{'api_value':info_baoxian},
      					       error:function(){

      					       	   $.toast("保险接口调用出错");},
      					       success:function(data){
      						     if(data.match("err_code")!=null){
      							    switch(JSON.parse(data).err_code)
      								{
      									case 40003:

      									   my.tokenExpire()
      									   break;
      									default:

      									   $.toast(JSON.parse(data).err_msg);
      								}
      						     }else{
      						     	     data=JSON.parse(data)
      								     data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								     for(i=0;i<data.length;i++){
      								     	 var option_str='<option title="'+data[i].insurance_combo_price+'" value="'+data[i].insurance_combo_id+'">'+data[i].insurance_combo_name+'('+config.danwei+data[i].insurance_combo_price+')'+'</option>'
      								         $('.bxtc_s').append(option_str)
      								     }
      								     var price=[]
      								     for(var i=0;i<$('.bxtc_s option').length;i++){
      								     	 price[i]=$('.bxtc_s option').eq(i).attr('title')
      								     }
      								     price=price.sort( function sortNumber(a,b)
                                            {
                                           return a - b
                                             }).pop()
                                         $('.bxtc div span:first-child').text(config.danwei+price)
                                         price='[title="'+price+'"]'
                                         $(price).attr('selected',true)
      								     $('.bxtc_s').change(function(){
      								     	$('.bxtc div span:first').text(config.danwei+$('.bxtc_s option:checked').attr('title'))
      								     })
      							}
      					    }
      			         })
      				//获取保险套餐end
      				//提交订单start
      				$('.orderDetails-submit').click(function(){
      					 $.confirm('您需在1小时内支付车辆租金，否则该订单将被取消', function () {
                             $.showPreloader()
      					$('.orderDetails-submit').addClass('active_btn')
      					var info_submit={
      						       user_id:my.getCookie('id'),
	                        	   order_daterent:details,
	                        	   order_baoxian:$('.bxtc_s option:checked').attr('title'),
	                        	   order_baoxianid:$('.bxtc_s').val(),
	                        	   order_youhui:$('.yhq_s option:checked').attr('title'),
	                        	   order_youhuiid:$('.yhq_s').val(),
      				      }
      					console.log(info_submit)
      				        info_submit=my.cryptoASEencrypt(JSON.stringify(info_submit),key)
      				        $.ajax({
      					       url:api.bookingorder,
      					       type: 'post',
      					       async:false,
      					       data:{'api_value':info_submit},
      					       error:function(){
      					       	   $.hidePreloader()
      					       	   $('.orderDetails-submit').removeClass('active_btn')
      					       	   $.toast("提交失败，请重试！");},
      					       success:function(data){
      					           $('.orderDetails-submit').removeClass('active_btn')
      						     if(data.match("err_code")!=null){
      						     	$('.orderDetails-submit').removeClass('active_btn')
      							    switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   $.hidePreloader()
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.hidePreloader()
      									   $.toast(JSON.parse(data).err_msg);
      								}
      						     }else{
      						     	     $.hidePreloader()
      						     	     data=JSON.parse(data)
      								     data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								     console.log(data)
                                         sessionStorage.waitfp_id=data.waitfp_id
      					                 sessionStorage.rental_orderid=data.rental_orderid
      					                 sessionStorage.orderid=data.rental_orderid
      					                // $.router.loadPage("zhifu_other.html");
                                     $.router.load(zhifu_otherUrl,true);
      							}
      					    }
      			         })
                         });

      				})
      				//提交订单end
      				//支付操作start
      				$('.get-car-hold').click(function(){
      				    $('.get-cash').hide();
      					$(this).hide()
      					//$.router.loadPage("rentalCarOrderDetails.html");
                        $.router.load(rentalCarOrderDetailsUrl,true);
      				})
      				$('.get-cash-e span:first-child').click(function(){
      					 $('.get-cash').hide();
      					 $('.get-car-hold').hide()
      					// $.router.loadPage("rentalCarOrderDetails.html");
                        $.router.load(rentalCarOrderDetailsUrl,true);
      				})
});